package com.huike.clues.service.impl;


import com.huike.clues.domain.TbClue;
import com.huike.clues.domain.TbClueTrackRecord;
import com.huike.clues.domain.vo.ClueTrackRecordVo;
import com.huike.clues.mapper.TbClueMapper;
import com.huike.clues.mapper.TbClueTrackRecordMapper;
import com.huike.clues.service.ITbClueTrackRecordService;
import com.huike.common.core.page.TableDataInfo;
import com.huike.common.utils.SecurityUtils;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 线索跟进记录Service业务层处理
 * @date 2022-04-22
 */
@Service
public class TbClueTrackRecordServiceImpl implements ITbClueTrackRecordService {

    @Autowired
    TbClueTrackRecordMapper tbClueTrackRecordMapper;

    @Autowired
    TbClueMapper tbClueMapper;

    /**添加线索跟进记录列表*/
    @Override
    public int insertClueTrackRecordVo(TbClueTrackRecord tbClueTrackRecord) {
        TbClue tbClue = new TbClue();
        BeanUtils.copyProperties(tbClueTrackRecord,tbClue);
        tbClue.setId(tbClueTrackRecord.getClueId());
        tbClueMapper.updateTbClue(tbClue);
        /*获取当前操作人的名字*/
        String username = SecurityUtils.getUsername();
        tbClueTrackRecord.setCreateBy(username);

        return tbClueTrackRecordMapper.insertClueTrackRecordVo(tbClueTrackRecord);
    }

    /**查询线索跟进记录列表*/
    @Override
    public TableDataInfo selectId(Long clueId) {
        TableDataInfo tableDataInfo = new TableDataInfo();

        List<TbClueTrackRecord> tbClueTrackRecord= tbClueTrackRecordMapper.selectId(clueId);

        tableDataInfo.setRows(tbClueTrackRecord);

        tableDataInfo.setCode(200);

        tableDataInfo.setTotal(tbClueTrackRecord.size());

        tableDataInfo.setMsg("查询成功");

        return tableDataInfo;
    }
}
